package reduce.fz.com.reduce.util;

import android.os.Environment;
import android.os.StatFs;

import java.io.File;

/**
 * SD卡的相关util方法
 * @auth lipf on 2015/1/12.
 */
public class SDUtil {

    /**
     * 是否存在SD卡
     * @return
     */
    public static boolean ifExitsSD(){
        String SDState = Environment.getExternalStorageState();
        return SDState.equals(Environment.MEDIA_MOUNTED);
    }
    /**
     * 获取SD卡的文件路径
     * @return
     */
    public static File getSDDir(){
        File sd = Environment.getExternalStorageDirectory();
        return sd;
    }
    /**
     * 返回SD卡的可用空间，按照KB计算
     * @return
     */
    public static long getSDAvailableSize(){
        File sd = Environment.getExternalStorageDirectory();
        StatFs statfs = new StatFs(sd.getPath());
        long blockSize = statfs.getBlockSizeLong();
        long ava = statfs.getAvailableBlocksLong();
        return blockSize*ava/1024;
    }

    /**
     * 返回SD卡的所有空间大小
     * @return
     */
    public static long getSDAllSize(){
        File sd = Environment.getExternalStorageDirectory();
        StatFs statfs = new StatFs(sd.getPath());
        long blockSize = statfs.getBlockSizeLong();
        long total = statfs.getBlockCountLong();
        return blockSize*total/1024;
    }
}
